using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Windows.Threading;

namespace Ricciolo.PaperBoy.Feeds
{
    public abstract class NotifyItem : INotifyPropertyChanged
    {
        private PropertyChangedEventHandler propertyChanged;

        private Dispatcher dispatcher;

        protected NotifyItem(Dispatcher dispatcher)
        {
            this.dispatcher = dispatcher;
        }

        protected Dispatcher Dispatcher
        {
            get { return this.dispatcher; }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged
        {
            add { this.propertyChanged += value; }
            remove { propertyChanged -= value; }
        }

        protected virtual void OnPropertyChanged(string propertyName)
        {
            this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
        }

        protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            if (propertyChanged != null)
                this.dispatcher.BeginInvoke(DispatcherPriority.DataBind, this.propertyChanged, this, e);
        }

        #endregion
    }

}
